<?php
namespace Seller\Model;
use Think\Model;
class ClassModel extends Model 
{
	public $tableName = 'class';

	//获取所有的商品分类
	public function index()
	{
		$areaModel = M($this->tableName);
		$res = $areaModel->select();
		return $res;
	}

	//获取一条的地区分类
	public function one($id, $tableName)
	{
		$class['class_id'] = $id;
		$areaModel = M($tableName);
		$res = $areaModel->where($class)->select();
		return $res;
	}

	//修改地区
	public function set($arr, $tableName)
	{
		$area['class_id'] = $arr['id'];
		$name['name'] = $arr['name'];
		$areaModel = M($tableName);
		$res = $areaModel->where($name)->select();
		if($res)
		{
			$saveUser = 'notIn';
		}else
		{
			$saveUser = $areaModel->data($arr)->where($area)->save();
		//var_dump($area);exit();
		}
		return $saveUser;
	}

	/*删除地区*/
	public function del($id ,$tableName)
	{
		$area['class_id'] = $id['class_id'];
		$areaModel     = M($tableName);
		$area_res      = $areaModel->where($area)->delete();
		//var_dump($area);exit();
		return $area_res;
	}

	/*增加地区*/
	public function areaAdd($arr, $tableName)
	{
		//var_dump($arr);exit();
		$areaModel     = M($tableName);
		$res = $areaModel->where($arr)->select();
		if($res)
		{
			$res_in = 'notIn';
		}else
		{
			$res_in = $areaModel->data($arr)->add();
		}
		return $res_in;
	}

}